package cn.qqtheme.framework.picker;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import cn.qqtheme.framework.icons.ColorPickerIcon;
import cn.qqtheme.framework.popup.ConfirmPopup;
import cn.qqtheme.framework.util.ConvertUtils;
import cn.qqtheme.framework.widget.ColorPanelView;
import cn.qqtheme.framework.widget.StrokeTextView;
import java.util.Locale;

/* loaded from: classes.dex */
public class ColorPicker extends ConfirmPopup<LinearLayout> {
    private static final int BLACK_ID = 2;
    private static final int MULTI_ID = 1;
    private ColorPanelView blackColorView;
    private StrokeTextView hexValView;
    private int initColor;
    private ColorPanelView multiColorView;
    private OnColorPickListener onColorPickListener;

    /* loaded from: classes.dex */
    public interface OnColorPickListener {
        void onColorPicked(int i);
    }

    public ColorPicker(Activity activity) {
        super(activity);
        this.initColor = -1;
        setHalfScreen(true);
        setTitleView(createTitleView(activity));
    }

    private View createTitleView(Activity activity) {
        this.hexValView = new StrokeTextView((Context) activity, true);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, ConvertUtils.toPx(activity, 28.0f));
        int px = ConvertUtils.toPx(activity, this.topPadding);
        layoutParams.leftMargin = px;
        layoutParams.rightMargin = px;
        layoutParams.addRule(14, -1);
        layoutParams.addRule(15, -1);
        this.hexValView.setLayoutParams(layoutParams);
        this.hexValView.setGravity(17);
        this.hexValView.setBackgroundColor(this.initColor);
        this.hexValView.setBorderColor(ConvertUtils.toDarkenColor(this.initColor, 0.6f));
        this.hexValView.setTextColor(this.initColor);
        this.hexValView.setShadowLayer(3.0f, 0.0f, 2.0f, -1);
        this.hexValView.setMinEms(6);
        this.hexValView.setMaxEms(8);
        this.hexValView.setPadding(0, 0, 0, 0);
        this.hexValView.setSingleLine(true);
        this.hexValView.setEnabled(false);
        return this.hexValView;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // cn.qqtheme.framework.popup.ConfirmPopup
    public LinearLayout makeCenterView() {
        LinearLayout linearLayout = new LinearLayout(this.activity);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        linearLayout.setOrientation(1);
        this.multiColorView = new ColorPanelView(this.activity);
        this.multiColorView.setId(1);
        this.multiColorView.setLayoutParams(new LinearLayout.LayoutParams(-1, 0, 1.0f));
        this.multiColorView.setPointerDrawable(ConvertUtils.toDrawable(ColorPickerIcon.getCursorTop()));
        this.multiColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() { // from class: cn.qqtheme.framework.picker.ColorPicker.1
            @Override // cn.qqtheme.framework.widget.ColorPanelView.OnColorChangedListener
            public void onColorChanged(ColorPanelView colorPanelView, int i) {
                ColorPicker.this.updateCurrentColor(i);
            }
        });
        linearLayout.addView(this.multiColorView);
        this.blackColorView = new ColorPanelView(this.activity);
        this.blackColorView.setId(2);
        this.blackColorView.setLayoutParams(new LinearLayout.LayoutParams(-1, ConvertUtils.toPx(this.activity, 30.0f)));
        this.blackColorView.setPointerDrawable(ConvertUtils.toDrawable(ColorPickerIcon.getCursorBottom()));
        this.blackColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() { // from class: cn.qqtheme.framework.picker.ColorPicker.2
            @Override // cn.qqtheme.framework.widget.ColorPanelView.OnColorChangedListener
            public void onColorChanged(ColorPanelView colorPanelView, int i) {
                ColorPicker.this.updateCurrentColor(i);
            }
        });
        linearLayout.addView(this.blackColorView);
        return linearLayout;
    }

    @Override // cn.qqtheme.framework.popup.BasicPopup
    protected void setContentViewAfter(View view) {
        this.multiColorView.setColor(this.initColor);
        this.multiColorView.setBrightnessGradientView(this.blackColorView);
    }

    @Override // cn.qqtheme.framework.popup.ConfirmPopup
    protected void onSubmit() {
        OnColorPickListener onColorPickListener = this.onColorPickListener;
        if (onColorPickListener != null) {
            onColorPickListener.onColorPicked(getCurrentColor());
        }
    }

    @Override // cn.qqtheme.framework.popup.BasicPopup
    public void dismiss() {
        super.dismiss();
    }

    public int getCurrentColor() {
        return Color.parseColor("#" + ((Object) this.hexValView.getText()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void updateCurrentColor(int i) {
        this.hexValView.setText(ConvertUtils.toColorString(i, false).toUpperCase(Locale.getDefault()));
        this.hexValView.setBorderColor(ConvertUtils.toDarkenColor(i, 0.6f));
        this.hexValView.setTextColor(i);
        this.hexValView.setBackgroundColor(i);
    }

    public void setInitColor(int i) {
        this.initColor = i;
    }

    public void setOnColorPickListener(OnColorPickListener onColorPickListener) {
        this.onColorPickListener = onColorPickListener;
    }
}
